package com.zhao.wechat.service;


import com.zhao.wechat.domain.UserInfo;
import com.zhao.wechat.repository.UserInfoRepository;
import com.zhao.wechat.rest.UserInfoRest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author stevezhao
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

	@Autowired
	private UserInfoRepository userInfoRepository;

	@Override
	public Page<UserInfo> queryUserPage(Integer current, Integer size) {
		if (current != null && size != null){
			// 设置分页
			PageRequest page = PageRequest.of(current, size);
			Page<UserInfo> infoPage = userInfoRepository.findAll(page);
			return infoPage;
		}
		return null;
	}

	@Override
	public void saveOrUpdate(UserInfo userInfo) {
		if (Objects.nonNull(userInfo)){
			userInfoRepository.save(userInfo);
		}
	}

	@Override
	public void deleteUserById(Long id) {
		if (Objects.nonNull(id)){
			userInfoRepository.deleteById(id);
		}
	}

	@Override
	public List<UserInfo> listUserInfo() {
		return userInfoRepository.findAll();
	}
}
